<?php
$wecha_id = $_GET['wecha_id'];
//实例化一个memcache对象
$datapath = str_replace("/shake", '/', dirname(__FILE__));
$configpath = $datapath . '/data/memcache.php';
if (file_exists($configpath)) {
    require($configpath);
    if ($use_memcache == 1) {
        $mem=new Memcache;
        $mem->connect($memcache_host, $memcache_port);
        hasmemcache($mem);
    }else{
        hasmysql();
    }
}else{
    hasmysql();
}

//judge=1 获取分数信息
//judge=2 获取人数
//judge=3 开始
//judge=4 结束
function hasmemcache($mem)
{
    global $wecha_id;
    $wall_state_key='wall_state';
    if($mem->get($wall_state_key)==2){//活动开始
        $prefix = 'xianchang_';
        $data = $mem->get($prefix . $wecha_id);
        if(!$data){
            //活动已经开始无法加入游戏
            echo json_encode(array(
                'status' => 5,
                'point' => 0
            ));
            return;
        }else{
            $data['point']=$data['point']+1;
            $mem->set($prefix.$wecha_id,$data,MEMCACHE_COMPRESSED, 3600);
            echo json_encode(array(
                'status' => 2,
                'point' => $data['point']
            ));
            return;
        }
    }else{
        echo json_encode(array(
            'status' => 3,
            'point' => 0
        ));
        return;
    }
   

}

function hasmysql()
{
    global $wecha_id;
    require('db.php');
    $ispen = $xuanzezu['isopen'];
    $pointnum = 0;
    $shake_toshake_m = new M('shake_toshake');
    $data = $shake_toshake_m->find('`wecha_id`="' . $wecha_id . '"', 'point');
    if ($data && $data['point'] >= 0 && $ispen == 2) {
        $sql_shake = 'UPDATE  `weixin_shake_toshake` SET  `point` = `point`+1  WHERE `wecha_id` = "'.$wecha_id.'";';
        $shake_toshake_m->query($sql_shake);
        $pointnum = $data['point'];
    } else {
        $ispen = 3;
    }
    $shake_toshake_m->close();
    echo json_encode(array(
        'status' => $ispen,
        'point' => $pointnum
    ));
    return;
}

?>

